<template>
  <div class="daybox">
    <div class="header">
      <van-nav-bar title="Today" border="false">
        <template #left>
          <i class="iconfont icon-shangdian icons"></i>
        </template>
        <template #right>
          <van-icon @click-right="onClickRight" name="plus" size="23" color="#060606" />
        </template>
      </van-nav-bar>
    </div>
    <div class="carousel">
      <van-swipe class="my-swipe" :autoplay="3000000" indicator-color="white" height="160">
        <van-swipe-item>
          <div class="swipe-boxone">
            <div class="swipe-left">
              <p class="swipe-boxone_p_1">『日运播报』</p>
              <div class="swipe-left_3ps">
                <p>2023年6月27日</p>
                <p>星期一</p>
                <p>今日幸运词：成长</p>
              </div>
            </div>
            <div class="swipe-right">
              <p><van-icon name="location-o" />南昌市</p>
              <p>29°</p>
              <p>局部多云</p>
            </div>
          </div>
        </van-swipe-item>
        <van-swipe-item>
          <div class="swipe-boxtwo">
            <p class="swipe-boxtwo-o">青春是一个短暂的美梦,当你醒来时,他早已消失无踪。青春是一个短暂的美梦,当你醒来时,他早已消失无踪。</p>
            <p class="swipe-boxtwo-l">——莎士比亚</p>
          </div>
        </van-swipe-item>
        <van-swipe-item>
          <div class="swipe-boxthree">

          </div>
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="ai">
      <van-loading class="loading" color="#1989fa" size="36" vertical v-show="state.loading" >请稍等，正在为您解答</van-loading>
      <div class="ai-header">知识问问</div>
      <div class="answer-box">
        <textarea v-model="answer" readonly>
         
        </textarea>
      </div>
      <div class="input-box">
        <input v-model="question"  placeholder="有问题可以问我哦~">
        <button @click="submitQuestion">发送</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import axios  from 'axios';
import { reactive } from 'vue';


const question = ref('')
const answer = ref('');

const state = reactive({
  loading: false,
})

const submitQuestion = () =>  {
  state.loading = true;
  axios.post('http://localhost:3000/openai', {
    question: question.value,
  }).then(res => {
    //console.log(res.data[0].message.content);
    answer.value = res.data[0].message.content
    state.loading = false
  })
}

</script>

<style lang="less" scoped>
.daybox {
  height: 100%;
  padding-bottom: 50px;

  .header {
    height: 46px;
    .icons{
      font-size: 26px;
    }
  }
  .carousel {
    .swipe-boxone,
    .swipe-boxtwo,
    .swipe-boxthree {
      height: 150px;
      margin: 10px 10px;
      border-radius: 10px;
      border: 1px solid #646464;

    }

    .swipe-boxone {
      background-color: rgb(68, 167, 191);
      display: flex;
      font-size: 16px;
      color: #ffffff;
      .swipe-left {
        width: 200px;
        margin: 15px;
        .swipe-boxone_p_1{
          font-size: 20px;
        }
        .swipe-left_3ps{
          margin: 10px 0 0 7px;
          p{
            margin: 7px 0;
          }
        }
      }

      .swipe-right {
        text-align: center;
        margin: 30px 0 15px 0;
        flex: 1;
        p{
          margin: 10px 0;
          
        }
      }
    }

    .swipe-boxtwo {
      background-color: bisque;
      font-size: 16px;

      .swipe-boxtwo-o {
        height: 72px;
        line-height: 150%;
        margin: 16px 18px;
      }

      .swipe-boxtwo-l {
        margin: 0 18px;
        text-align: right;
      }
    }

    .swipe-boxthree {
      background-color: rgb(255, 135, 83);
      font-size: 16px;
    }
  }
  .ai{
    height: 440px;
    margin: 20px 10px 10px;
    border: 2px solid #1b6ef3;
    border-radius: 10px;
    background-color: #ebebeb;
    position: relative;
    .loading{
      position: absolute;
      top: 45%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
    .ai-header{
      height: 30px;
      background: #1b6ef3;
      font-size: 18px;
      color: #ffffff;
      text-align: center;
      line-height: 30px;
      overflow: hidden;
    }
    .answer-box{
      textarea{
        width: 371px;
        height: 340px;
        margin: 10px;
        border: none;
        font-size: 16px;
      }
    }
    .input-box{
      display: flex;
      font-size: 16px;
      margin: 0 10px;
      input{
        width: 84%;
        height: 30px;
        margin-right: 11px;
        border: none;
        border-radius: 5px;
      }
      button{
        border-radius: 5px;
        width: 50px;
        border: none ;
        background-color: #ffffff;
      }
    }
    
  }
}
</style>

<style>
.van-swipe__indicators {
  left: 85%
}

.van-swipe__indicator {
  width: 8px;
  height: 8px;
  background-color: rgb(190, 193, 196);
}
</style>